package cn.itsource.blog.service.impl;

import cn.itsource.blog.domain.Article;
import cn.itsource.blog.domain.ArticleType;
import cn.itsource.blog.mapper.ArticleMapper;
import cn.itsource.blog.mapper.ArticleTypeMapper;
import cn.itsource.blog.query.ArticleQuery;
import cn.itsource.blog.service.IArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class ArticleServiceImpl implements IArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    @Transactional
    public void add(Article article) {
        // 新增
        articleMapper.add(article);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        // 删除
        articleMapper.delete(id);
    }

    @Override
    public Article get(Long id) {
        // 查询单个
        return articleMapper.get(id);
    }

    @Override
    public List<Article> getAll() {
        // 查询所有
        return articleMapper.getAll();
    }

    @Override
    @Transactional
    public void delPatch(Long[] ids) {
        // 批量删除
        articleMapper.delPatch(ids);
    }

    @Override
    @Transactional
    public PageInfo<Article> pageInfo(ArticleQuery articleQuery) {
        // 设置参数
        PageHelper.startPage(articleQuery.getCurrentPage(),articleQuery.getPageSize());
        // 查询用户信息
        List<Article> articles = articleMapper.getAllByQuery(articleQuery);
        // 返回查询结果
        return new PageInfo<>(articles);
    }

    @Override
    @Transactional
    public void updata(Article article) {
        // 修改
        articleMapper.update(article);
    }




}
